import { ProFormCheckbox } from '@ant-design/pro-components';
import type { ProFormCheckboxGroupProps } from '@ant-design/pro-form/lib/components/Checkbox/index';

const CommonFormCheckbox: React.FC<ProFormCheckboxGroupProps> = ({
  required,
  rules = [],
  ...props
}) => {
  return (
    <ProFormCheckbox.Group
      {...props}
      rules={
        rules.some((rule) => 'required' in rule)
          ? rules
          : [
              {
                required,
                message: `请选择${props.label}`,
              },
              ...rules,
            ]
      }
    />
  );
};

CommonFormCheckbox.defaultProps = { required: false };

export default CommonFormCheckbox;
